﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceProcess;
using System.Diagnostics;
using System.Windows.Forms;
using Updater.Common;
using System.Data;
using System.Linq;
using System.Text;
using log4net;
using System;

namespace Updater.Service
{
    public partial class Service : ServiceBase
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Service));
        Updater.Common.Downloader m_Downloader;

        public Service()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            // Uncomment this if you want to debug the service.
            // in order to debug the service you need to install it
             m_Downloader = new Updater.Common.Downloader();

            try
            {
                
                m_Downloader.Start();
                EventLog.WriteEntry("UpdaterService Started");
                log.Info("Started");

                
            }
            catch (Exception exception)
            {
                log.Error("Problem when trying to start", exception);
            }
        }

        protected override void OnStop()
        {
           try
           {
                m_Downloader.Stop();
                EventLog.WriteEntry("UpdaterService Stopped");
                log.Info("Stopped");
           }

           catch (Exception exception)
           {
                log.Error("Problem when trying to stop", exception);
           }
        }
    }
}
